﻿using System;
using System.Collections.Generic;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace OutlookAddIn_Collaboratori
{
    /// <summary>
    /// This class tracks the state of an Outlook inspector window for the 
    /// add-in and ensures that Ribbon and item state is handled correctly.
    /// </summary>

    public class OutlookInspector
    {
        #region Instance Variables

        private Outlook.Inspector   m_Window;
        private OutlookItem         m_CurrentOutlookItem;

        #endregion

        #region Properties
        /// <summary>
        /// The actual Outlook inspector window wrapped by this instance
        /// </summary>
        internal Outlook.Inspector Window
        {
            get { return m_Window; }
        }
        /// <summary>
        /// The CurrentItem for this inspector window.
        /// </summary>
        internal OutlookItem OutlookItem
        {
            get { return m_CurrentOutlookItem; }
        }
        #endregion

        #region Events
        public event EventHandler Close;
        #endregion
        #region Constructor
        /// <summary>
        /// Create a new instance of the tracking class for an inspector 
        /// </summary>
        /// <param name="inspector">The new inspector window to monitor</param>
        ///<remarks></remarks>
        public OutlookInspector(Outlook.Inspector inspector)
        {
            m_Window = inspector;
            m_CurrentOutlookItem = new OutlookItem(inspector.CurrentItem);
        }
        #endregion
        #region Event Handlers
        private void OutlookWindow_Close()
        {
            // Raise the OutlookInspector close event
            if (Close != null)
            {
                Close(this, EventArgs.Empty);
            }
            m_Window = null;
            m_CurrentOutlookItem = null;
        }
        #endregion

    }
}
